package com.example.ktsb.repository

import com.example.ktsb.entity.User
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface UserRepository : JpaRepository<User, Long> {

    // 此处是spring-boot-data-jdbc 而非 spring-boot-data-jpa
    // 无法写出入参user动态条件的查询，只能通过在service里写判断逻辑
    @Query(
        "select * from user u where u.user_name= :userName",
        nativeQuery = true
    )
    fun getUser(@Param("userName") userName: String?): List<User>

    fun findByUserNameLikeIgnoreCase(userName: String): List<User>

    fun findByStatus(status: Int, pageable: Pageable): Page<User>

}